import 'package:flutter/material.dart';

class Taskitem extends StatefulWidget {
  Taskitem({super.key, required this.item});
  Map item;

  @override
  State<Taskitem> createState() => _TaskitemState();
}

class _TaskitemState extends State<Taskitem> {
  Map item = {};

  @override
  void initState() {
    super.initState();
    // print(widget.item);
    setState(() {
      item = widget.item;
    });
  }

//获取订单状态
  _getStatus(int status) {
    String data = '';
    switch (status) {
      case 1:
        data = '待提货';
        break;
      case 2:
        data = '在途';
        break;
      case 3:
        data = '改派';
        break;
      case 4:
        data = '已交付';
        break;
      case 5:
        data = '已作废';
        break;
    }
    return data;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(left: 16, right: 16, top: 10, bottom: 10),
      width: MediaQuery.of(context).size.width,
      height: 200,
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(10)),
      child: Column(
        children: [
          //第一行任务编号
          Row(
            children: [
              Expanded(
                  child: Text(
                '任务编号:${item['transportTaskId']}',
                style: const TextStyle(
                    fontWeight: FontWeight.w500,
                    color: Color.fromRGBO(42, 41, 41, 1)),
              )),
              Container(
                padding: const EdgeInsets.all(1),
                width: 50,
                height: 22,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(11),
                    border: Border.all(color: Colors.red, width: 1)),
                child: const Text(
                  '已延迟',
                  textAlign: TextAlign.center,
                  style: TextStyle(color: Colors.red, fontSize: 12),
                ),
              )
            ],
          ),
          const SizedBox(
            height: 20,
          ),
          //起始位置
          Row(
            children: [
              // Text('始'),
              Container(
                width: 22,
                height: 22,
                decoration: const BoxDecoration(
                  color: Colors.black,
                  //设置边框圆角
                  borderRadius: BorderRadius.all(Radius.circular(11)),
                ),
                child: const Text(
                  '起',
                  textAlign: TextAlign.center,
                  style: TextStyle(
                      color: Colors.white, fontWeight: FontWeight.w500),
                ),
              ),
              const SizedBox(
                width: 20,
              ),
              Expanded(
                  child: Text(
                item['startAddress'] ?? '',
                maxLines: 2,
                style: const TextStyle(
                  fontSize: 14,
                  color: Color.fromRGBO(129, 129, 129, 1),
                  overflow: TextOverflow.ellipsis,
                ),
              ))
            ],
          ),
          const SizedBox(
            height: 14,
          ),
          Row(
            children: [
              Container(
                width: 22,
                height: 22,
                decoration: const BoxDecoration(
                  color: Colors.red,
                  //设置边框圆角
                  borderRadius: BorderRadius.all(Radius.circular(11)),
                ),
                child: const Text(
                  '止',
                  textAlign: TextAlign.center,
                  style: TextStyle(
                      color: Colors.white, fontWeight: FontWeight.w500),
                ),
              ),
              const SizedBox(
                width: 20,
              ),
              Expanded(
                  child: Text(
                maxLines: 2,
                item['endAddress'] ?? '',
                style: const TextStyle(
                  fontSize: 14,
                  color: Color.fromRGBO(129, 129, 129, 1),
                  overflow: TextOverflow.ellipsis,
                ),
              ))
            ],
          ),
          const SizedBox(
            height: 14,
          ),
          //分割线
          const Divider(
            height: 1,
            color: Colors.grey,
          ),
          const SizedBox(
            height: 10,
          ),
          //提货时间
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              //左侧
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const Text(
                    '提货时间：',
                  ),
                  Text(
                    item['planArrivalTime'] ?? '',
                    style: const TextStyle(),
                  ),
                ],
              ),

              //右侧按钮
              SizedBox(
                width: 100, // 设置宽度
                height: 32, // 设置高度
                child: ElevatedButton(
                  style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
                  onPressed: () {},
                  child: Text(
                    '${_getStatus(item['status'])}',
                    textAlign: TextAlign.center,
                    style: const TextStyle(color: Colors.white, fontSize: 14),
                  ),
                ),
              )
            ],
          )
        ],
      ),
    );
  }
}
